home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "Module1"
- Global wrkJet As Workspace
- Global dbs As Database
- Global SQL As SQLInfo
- Global ReportType As String
-
- Public Sub GetTables(cbo As ComboBox)
-
- Dim NumTables As Integer
-
- ' Fill in combo with table names.
- For NumTables = 0 To wrkJet.Databases(0).TableDefs.Count - 1
- cbo.AddItem wrkJet.Databases(0).TableDefs(NumTables).Name
- Next NumTables
-
- End Sub
-
- Public Sub GetColumns(lst As ListBox, TableName As String)
-
- Dim NumColumns As Integer
-
- ' Fill in listbox with column names.
- For NumColumns = 0 To wrkJet.Databases(0).TableDefs(TableName).Fields.Count - 1
- lst.AddItem wrkJet.Databases(0).TableDefs(TableName).Fields(NumColumns).Name
- Next NumColumns
-
- End Sub
-
- Public Sub PopulateSheet()
- Dim pConnect As String
- Dim pQuery As String
- Dim SQLFields As String
- Dim GroupFields As String
- Dim pRetCode As Integer
- Dim x As Integer
- Dim NumColumns As Integer
-
- pConnect = "DSN=Southcreek;DBQ=F:\VCI\VcDbC\database\Southcrk.mdb;DefaultDir=F:\VCI\VcDbC\database\;DriverId=25;FIL=MS Access;MaxBufferSize=512;PageTimeout=5;UID=admin;"
-
- If SQL.Fields.Count = 0 Then
- For NumColumns = 0 To wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count - 1
- SQL.Fields.Add wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(NumColumns).Name, wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(NumColumns).Name
- Next NumColumns
- End If
-
- For x = 1 To SQL.Fields.Count
- SQLFields = SQLFields & SQL.Fields.Item(x).Name & ", "
- Next x
-
- For x = 1 To SQL.Groups.Count
- GroupFields = GroupFields & SQL.Groups.Item(x).Name & ", "
- Next x
-
- SQLFields = Left(SQLFields, Len(SQLFields) - 2)
- If SQL.Groups.Count > 0 Then
- GroupFields = " Group By " & SQLFields & " Order By " & Left(GroupFields, Len(GroupFields) - 2)
- End If
- pQuery = "Select " & SQLFields & " From " & SelectFields.cboTables.Text & GroupFields
-
- ReportWriter.F1Book1.ODBCConnect pConnect, True, pRetCode
- ReportWriter.F1Book1.ODBCQuery pQuery, 1, 1, False, True, True, True, False, pRetCode
- ReportWriter.F1Book1.ODBCDisconnect
-
- Select Case ReportType
- Case "Report Wizard"
- Call ReportWizardFormat
- Case "AutoReport: Tabular"
- Call FormatTabular
- End Select
- Debug.Print pConnect
- End Sub
-
- Public Sub FormatTabular()
- Dim x As Integer
- Dim NumColumns As Integer
-
- NumColumns = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count
- With ReportWriter.F1Book1
- .ShowRowHeading = False
- .ShowColHeading = False
- .ShowGridLines = False
- .PrintGridLines = False
-
- .SetSelection -1, -1, -1, -1
- .FontSize = 8
-
- .InsertRange 1, 1, 2, 256, F1ShiftRows
- .TextRC(1, 1) = SelectFields.cboTables.Text
- .SetSelection 1, 1, 1, 1
- .FontBold = True
- .FontItalic = True
- .FontSize = 18
- .FontColor = RGB(0, 0, 128)
-
- For x = 0 To NumColumns - 1
- .TextRC(2, x + 1) = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields(x).Name
- .SetSelection 2, x + 1, 2, x + 1
- .FontBold = True
- .FontItalic = True
- .FontSize = 10
- .FontColor = RGB(0, 0, 128)
- Next x
-
- .SetSelection 2, 1, 2, NumColumns
- .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
-
- .SetRowHeightAuto -1, -1, -1, -1, False
-
- .ShowSelections = F1Off
- .ShowTabs = F1TabsOff
-
- .FixedRows = 2
- .PrintTitles = "$A$1:$IV$2"
-
- End With
- End Sub
-
-
- Public Sub PopulateColumnar()
- Dim RecordCount As Long
- Dim ColumnCoun As Long
- Dim RecSet As Recordset
- Dim nRow As Long
- Dim x As Integer
- Dim y As Integer
-
- nRow = 0
-
- With ReportWriter.F1Book1
- .ShowRowHeading = False
- .ShowColHeading = False
- .ShowGridLines = False
- .ShowSelections = F1Off
- .PrintGridLines = False
-
- .SetSelection -1, -1, -1, -1
- .FontSize = 8
-
- .SetSelection -1, 1, -1, 1
- .FontBold = True
- .FontItalic = True
- .FontSize = 10
- .FontColor = RGB(0, 0, 128)
-
- .TextRC(1, 1) = SelectFields.cboTables.Text
- .SetSelection 1, 1, 1, 1
- .FontBold = True
- .FontItalic = True
- .FontSize = 18
- .FontColor = RGB(0, 0, 128)
-
- ' .SetSelection -1, 3, -1, 3
- ' .SetBorder -1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0
- .SetSelection 1, 3, 1, 3
- .SetBorder 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0
- .SetSelection 1, 1, 1, 3
- .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
-
- .FixedRows = 1
- .PrintTitles = "$A$1:$IV$1"
-
- End With
-
- Set RecSet = dbs.OpenRecordset("Select * From " & SelectFields.cboTables.Text)
-
- RecSet.MoveLast
- RecSet.MoveFirst
-
- nRow = 1
-
- RecordCount = RecSet.RecordCount
- ColumnCount = wrkJet.Databases(0).TableDefs(SelectFields.cboTables.Text).Fields.Count
-
- For x = 1 To RecordCount
- For y = 0 To ColumnCount - 1
- nRow = nRow + 1
- If nRow >= ReportWriter.F1Book1.MaxRow Then
- Exit For
- End If
- ReportWriter.F1Book1.TextRC(nRow, 1) = RecSet.Fields(y).Name
- If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
- ReportWriter.F1Book1.TextRC(nRow, 3) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
- End If
- Next y
- If nRow < ReportWriter.F1Book1.MaxRow Then
- nRow = nRow + 1
- ReportWriter.F1Book1.AddRowPageBreak nRow
- End If
- RecSet.MoveNext
- Next x
-
- ReportWriter.F1Book1.SetColWidthAuto -1, -1, -1, -1, False
- ReportWriter.F1Book1.SetRowHeightAuto -1, -1, -1, -1, False
- End Sub
-
- Public Sub ReportWizardFormat()
- Dim x As Integer
-
- With ReportWriter.F1Book1
- .ShowRowHeading = False
- .ShowColHeading = False
- .ShowGridLines = False
- .ShowTabs = F1TabsOff
- .PrintGridLines = False
-
- .SetSelection -1, -1, -1, -1
- .FontSize = 8
-
- For x = 1 To SQL.Groups.Count
- .SetSelection -1, x, -1, x
- .FontBold = True
- .FontSize = 10
- .FontColor = RGB(0, 0, 128)
- Next x
-
- .SetSelection 1, 1, 1, 1
- .FontBold = True
- .FontItalic = True
- .FontSize = 18
- .FontColor = RGB(0, 0, 128)
-
- .SetSelection 2, -1, 2, -1
- .FontBold = True
- .FontItalic = True
- .FontSize = 10
- .FontColor = RGB(0, 0, 128)
- .SetBorder -1, -1, -1, -1, 5, 0, 0, 0, 0, 0, RGB(0, 0, 128)
-
- .SetColWidthAuto -1, -1, -1, -1, False
- .SetRowHeightAuto -1, -1, -1, -1, False
-
- .FixedRows = 2
- .PrintTitles = "$A$1:$IV$2"
-
- End With
-
- End Sub
-
- Public Sub PopulateReportWizard()
- Dim RecordCount As Long
- Dim ColumnCoun As Long
- Dim RecSet As Recordset
- Dim nRow As Long
- Dim nCol As Long
- Dim x As Integer
- Dim y As Integer
- Dim z As Integer
- Dim pQuery As String
- Dim isgroup As Boolean
-
- ReportWriter.F1Book1.TextRC(1, 1) = SelectFields.cboTables.Text
-
- For x = 1 To SQL.Groups.Count
- SQLFields = SQLFields & SQL.Groups.Item(x).Name & ", "
- Next x
-
- For x = 1 To SQL.Fields.Count
- If InStr(SQLFields, SQL.Fields(x).Name) = 0 Then
- SQLFields = SQLFields & SQL.Fields.Item(x).Name & ", "
- End If
- Next x
-
- For x = 1 To SQL.Groups.Count
- GroupFields = GroupFields & SQL.Groups.Item(x).Name & ", "
- Next x
-
- SQLFields = Left(SQLFields, Len(SQLFields) - 2)
- If SQL.Groups.Count > 0 Then
- GroupFields = " Group By " & SQLFields & " Order By " & Left(GroupFields, Len(GroupFields) - 2)
- End If
- pQuery = "Select " & SQLFields & " From " & SelectFields.cboTables.Text & GroupFields
-
- ReDim GroupArray(1, SQL.Groups.Count) As String
-
- For x = 1 To SQL.Groups.Count
- GroupArray(1, x) = SQL.Groups(x).Name
- Next x
-
- Set RecSet = dbs.OpenRecordset(pQuery)
-
- RecSet.MoveLast
- RecSet.MoveFirst
-
- nRow = 1
- nCol = 1
- RecordCount = RecSet.RecordCount
- ColumnCount = RecSet.Fields.Count
-
- For x = 1 To RecordCount
- nRow = nRow + 1
-
- If x = 1 Then
- For y = 0 To ColumnCount - 1
- ReportWriter.F1Book1.TextRC(nRow, nCol) = RecSet.Fields(y).Name
- If y = ColumnCount - 1 Then
- nRow = nRow + 1
- End If
- nCol = nCol + 1
- Next y
- End If
- For y = 0 To ColumnCount - 1
- If nRow >= ReportWriter.F1Book1.MaxRow Then
- Exit For
- End If
- For z = 1 To SQL.Groups.Count
- If RecSet.Fields(y).Name = SQL.Groups(z).Name Then
- If GroupArray(1, z) <> RecSet.Fields(RecSet.Fields(y).Name).Value Then
- If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
- ReportWriter.F1Book1.TextRC(nRow, nCol) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
- End If
- End If
- If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
- GroupArray(1, z) = RecSet.Fields(RecSet.Fields(y).Name).Value
- End If
- nCol = nCol + 1
- End If
- Next z
- If Not IsNull(RecSet.Fields(RecSet.Fields(y).Name).Value) Then
- ReportWriter.F1Book1.TextRC(nRow, nCol) = RTrim(RecSet.Fields(RecSet.Fields(y).Name).Value)
- End If
- nCol = nCol + 1
- Next y
- RecSet.MoveNext
- nCol = 1
- Next x
-
- For x = 1 To SQL.Groups.Count
- ReportWriter.F1Book1.DeleteRange 3, x + 1, 16383, x + 1, F1ShiftHorizontal
- Next x
-
- Call ReportWizardFormat
-
- End Sub
-